import * as types from '../actions/actionTypes';

const initCartData = {
    // 加入购物车
    datePickerOpen: true,
    // 购物车
    total: 0,
    cartList: [],
    allChecked:  false,
    checkedNum: 0,
    checkedPrice: 0,
    // 购物车结算
    totalPrice: 0,
    realPayPrice: 0,
    reducePrice: 0,
    customerList: [],
    contactData: {}
}

export default function cartModule(state = initCartData, action) {
    switch(action.type){
        case types.SET_DATE_PICKER_OPEN:
            return {
                ...state,
                datePickerOpen: action.open
            }
        // 获取购物车数据
        case types.GET_CART_LIST_DATA:
            return {
                ...state,
                total: action.total,
                cartList: action.cartList
            }
        // 选中更改数据
        case types.MODIFY_CART_LIST_DATA:
            return {
                ...state,
                cartList: action.cartList
            }
        // 全选/全不选
        case types.All_CHECK_CART_LIST_DATA:
            return {
                ...state,
                allChecked: action.checked
            }
        // 已选中商品和总价
        case types.CHECKED_LIST_CART_DATA:
            return {
                ...state,
                checkedNum: action.checkedNum,
                checkedPrice: action.checkedPrice
            }
        // 实际支付价格
        case types.REAL_PAY_PRICE: 
            return {
                ...state,
                totalPrice: action.totalPrice,
                reducePrice: action.reducePrice,
                realPayPrice: action.realPayPrice
            }
        // 游客信息
        case types.GET_CUSTOMER_LIST: 
            return {
                ...state,
                customerList: action.data
            }
        // 联系人信息
        case types.FILL_IN_CONTACT_FORM:
            return {
                ...state,
                contactData: action.data
            }
        default: 
            return state
    }
}